package com.qf.j2205.service.impl;

import com.qf.j2205.dao.ScreeningsMapper;
import com.qf.j2205.entity.Screenings;
import com.qf.j2205.service.ScreeningsService;
import com.qf.j2205.util.MybitesUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ScreeningsServiceImpl
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/15 19:28
 * @Version 1.0
 **/
public class ScreeningsServiceImpl implements ScreeningsService {
    @Override
    public boolean insertScreenings(Screenings scre) {
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);
        int i = mapper.insertScreenings(scre);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }

    /**
     * 根据id查询一条数据
     *
     * @param id
     * @return
     */
    public Screenings findOneById(int id) {
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);
        Screenings scre = null;
        scre = mapper.findOneById(id);
        return scre;
    }

    @Override
    public List<Screenings> selectScreenings() {
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);
        List<Screenings> lists = null;
        lists = mapper.selectScreenings();
        MybitesUtil.closeAll();
        return lists;
    }

    @Override
    public boolean deleteScreenings(int id) {
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);
        int i = mapper.deleteScreenings(id);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }

    /**
     * 根据id审核
     *
     * @param id
     * @return
     */
    public boolean checkScreenings(int id) {

        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);

        int i = mapper.checkScreenings(id);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }

    /**
     * 更新数据
     *
     * @param screenings
     * @return
     */
    @Override
    public boolean updateScreenings(Screenings screenings) {
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);

        int i = mapper.updateScreenings(screenings);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }


    /**
     * 根据开始时间和审核状态查询
     *
     * @param time
     * @param isAudit
     * @return
     */
    @Override
    public List<Screenings> selectTimeAndIsaudit(String time, String isAudit) {
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);
        List<Screenings> lists = null;
        lists = mapper.selectTimeAndIsaudit(time, isAudit);
        MybitesUtil.closeAll();
        return lists;
    }

    /**
     * 审核全部选中
     * @param det
     * @return
     */
   @Override
    public boolean detectAll(String det){
        ScreeningsMapper mapper = MybitesUtil.getSession().getMapper(ScreeningsMapper.class);
        String[] split = det.split(",");
        List<Integer> ints=new ArrayList<Integer>();
        for (String s : split) {
            ints.add(Integer.parseInt(s.trim()));
        }
        int i = mapper.detectAll(ints);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }
}
